local skill = fk.CreateSkill {
  name = "lvshi__drowning_skill",
}
local ls = require "packages/lvshi/utility"

Fk:loadTranslationTable{
  ["#lvshi__drowning_skill_throw"] = "你可弃置一张锦囊牌令%src执行两项",
}

skill:addEffect("cardskill", {
  prompt = "#lvshi__drowning_skill",
  target_num = 1,
  mod_target_filter = function(self, player, to_select, selected, card)
    return to_select ~= player-- and #to_select:getCardIds("e") > 0
  end,
  target_filter = Util.CardTargetFilter,
  on_use = function(self, room, use)
    local choice = ls.strategytrickuse(use.from, use.card, "drowning_scheme", "drowning_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    local damageType = fk.NormalDamage
    if effect.extra_data.strategy == "drowning_scheme" then
      damageType = fk.IceDamage
    end
    local courage = false
    if effect.extra_data.strategy == "drowning_courage" then
      local params = {
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name = "drowning_skill",
        cancelable = true,
        pattern = ".|.|.|.|.|trick",
        prompt = "#lvshi__drowning_skill_throw:"..to.id
      }
      local cards = room:askToDiscard(from, params)
      if #cards > 0 then courage = true end
    end  
    if #to:getCardIds("e") == 0 or courage or
      not room:askToSkillInvoke(to, {
      skill_name = skill.name,
      prompt = "#drowning-discard::"..from.id,
      }) then
      room:damage({
        from = from,
        to = to,
        card = effect.card,
        damage = 1,
        damageType = damageType,
        skillName = skill.name,
      })
      if courage and not to.dead then
        to:throwAllCards("e")
      end
    else
      to:throwAllCards("e")
    end
  end,
})

return skill